﻿@extends('layout.wechat_frame')

@section('main')
    <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">投标报价-报价</h1>
    </header>

    <div class="mui-content">

        <form method="post" action="{{ route('bidQuote.bqDetail.saveOffer', ['demand' => $demand->id])}}">

            {!! csrf_field() !!}

        <ul class="mui-table-view mui-table-view-striped mui-table-view-condensed">
            <li class="mui-table-view-cell">
                <!-- 错误消息与 验证方法的  Validator 的 $rules 对应-->
                @if ($errors->has('quantity_caps'))
                    <p style="color:#f50000"> {{ $errors->first('quantity_caps') }}</p>
                @endif
                @if ($errors->has('price'))
                        <p style="color:#f50000"> {{ $errors->first('price') }}</p>
                @endif
                @if ($errors->has('delivery_mode'))
                    <p style="color:#f50000"> {{ $errors->first('delivery_mode') }}</p>
                @endif
                <h4 class="mui-ellipsis"><span>物料名称:</span><span>{{ $goods->name }}</span></h4>
                <?php
                $assign_rule = json_decode($demand->assign_rule);
                $assign_rule_data = $assign_rule->rules;
                $assign_rule_data = json_decode($assign_rule_data, true);
                $assign = array_filter($assign_rule_data);
                $min_assign = min($assign);
                $assign_rule_data = implode('%；', $assign_rule_data).'%';
                ?>

                <h5 class="mui-ellipsis"><span class="ips-span-first">采购方</span><span >{{ $demand->company->name }}</span></h5>
                <h5 ><span class="ips-span-first">公司地址</span><span class="ips-span-input"><marquee  style="position:relative; top:6px; right:0px;" scrollAmount="2" width="196px">{{ $demand->company->delivery_address }}</marquee></span></h5>
                <h5 class="mui-ellipsis"><span class="ips-span-first">采购数量</span><span>{{ strval((float)$demand->quantity) }}</i> {{ $goods->unit }}</span></h5>
                <h5 class="mui-ellipsis"><span class="ips-span-first">分配方案</span><span>{{ $assign_rule->name }}【{{ $assign_rule_data }}】</span></h5>
                <h5 class="mui-ellipsis"><span class="ips-span-first">发票类型</span><span>{{ $demand->invoice }}</span></h5>
                <h5 class="mui-ellipsis"><span class="ips-span-first">付款方式</span><span>{{ $demand->payment }}</span></h5>
                <h5 class="mui-ellipsis"><span class="ips-span-first">报价有效期</span><span>招投标结束后{{ $demand->price_validity }}小时</span></h5>
                <h5 class="mui-ellipsis"><span class="ips-span-first">交货时间</span><span>{{ $demand->delivery_date_start }} 至 {{ $demand->delivery_date_stop }}</span></h5>
                <h5 class="mui-ellipsis"><span class="ips-span-first">最低成交量</span><span>{{ strval(($demand->quantity*$min_assign)/100) }}</i> {{ $goods->unit }}</span></h5>

                <h5 class="mui-ellipsis"><span class="ips-span-first">最高成交量</span><span class="ips-span-input">
                <input type="text" class="ips-inputtext" name="quantity_caps" value="{{ (!empty($offer) and is_null($offer->reason))?strval((float)$offer->quantity_caps):'' }}"></span><span> {{ $goods->unit }}</span>
                </h5>
                <h5 class="mui-ellipsis"><span class="ips-span-first">供方报价</span><span class="ips-span-input">
			<input type="text" class="ips-inputtext" name="price" value="{{ (!empty($offer) and is_null($offer->reason))?strval((float)$offer->price):'' }}"></span><span> 元/{{ $goods->unit }}</span>
                </h5>

                <h5 class="mui-ellipsis"><span class="ips-span-first">交货地点</span><span>
                        <?php
                        // lvze add 20160908 取得 到货方式 交货地点
                        $delivery_mode = \App\DeliveryMode::orderBy('created_at')->whereNull('deleted_at')->where('id', $demand->delivery_mode_id)->first();
                        ?>
                            @if(!empty($delivery_mode) and !is_null($delivery_mode->delivery_place))
                                {{ $delivery_mode->delivery_place}}
                            @endif

                        </span>
                    </h5>

                    <h5 class="mui-ellipsis" hidden><span class="ips-span-first">到货方式</span>
                        <span id='showUserPicker' class="ips-text-blue">
                            @if(!empty($offer) and is_null($offer->reason))
                                {{ $offer->delivery_mode }} - {{ $offer->delivery_costs }}元/{{ $goods->unit }}
                        @else
                            选择
                        @endif
                    </span>

                    <input type="text" id="pickerValue" name="delivery_mode" value="{{ (!empty($offer) and is_null($offer->reason))?strval($offer->delivery_costs.','.$offer->delivery_mode):'' }}" hidden>

                </h5>
            </li>
        </ul>
        <div class="mui-content-padded ips-detail-page-bottom">
            <div class="mui-button-row">
                <button  id="doWorkButton" type="submit" class="mui-btn mui-btn-primary" >提交报价</button>
            </div>
        </div>
        </form>
    </div>


@section('js')

    <script type="text/javascript">
        // 到货选择
        (function($, doc) {
            $.init();
            $.ready(function() {
                //普通示例
                var userPicker = new $.PopPicker();
                userPicker.setData([
                    {
                        value: '0.00,到库',
                        text: '到库 - 0元/{{ $goods->unit }}'
                    },
                @foreach ($demand->company->delivery_modes as $mode)
                    {
                        value: '{{ $mode->costs.','.$mode->mode }}',
                        text: '{{ $mode->mode }} - {{ $mode->costs }}元/{{ $goods->unit }}'
                    },
                @endforeach
                ]);
                var showUserPickerButton = doc.getElementById('showUserPicker');
                var userResult = doc.getElementById('showUserPicker');
                var pickerValue = doc.getElementById('pickerValue');

                showUserPickerButton.addEventListener('tap', function(event) {
                    userPicker.show(function(items) {
                        userResult.innerText = items[0].text;
                        pickerValue.value = items[0].value;
                        //返回 false 可以阻止选择框的关闭
                        //return false;
                    });
                }, false);
            });
        })(mui, document);

    </script>

@stop